//提示管理.

cc.Class({
    extends: cc.Component,

    properties: {
        gameNode:{
            default: null,
            type: cc.Node
        },
        playerNode:{
            default: null,
            type: cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        if(!Global.isFirstIn){
            this.node.active = false;
            return;
        }
        console.log('本地第一次进入游戏');
        this.player = this.playerNode.getComponent('Player');
        this.node.on('touchstart',this.onTouchStart,this);
        //所有的子节点.
        this.children = this.node.children;
        this.currentPage = -1;
        this.turnNextHint();
    },

    start () {

    },

    // update (dt) {},

    //跳过教程.
    skipHint: function(){
        //已经进行过新手教程,本地不再显示.
        cc.sys.localStorage.setItem('first','false');
        Global.isFirstIn = false;
        console.log('新手教程结束');
        this.gameNode.getComponent('Game').setTouchControl();
        this.node.active = false;
        this.player.play();
    },
    
    onTouchStart: function(e){
        if(this.currentPage == 2){
            this.playerJump();
            return;
        }
        this.turnNextHint();
    },

    //显示下一个提示.
    turnNextHint(){
        if(this.currentPage >= 0 && this.currentPage <= this.children.length - 1){
            this.children[this.currentPage].active = false;
        }
        this.currentPage++;
        if(this.currentPage >= 0 && this.currentPage <= this.children.length - 1){
            this.children[this.currentPage].active = true;
        }
        if(this.currentPage == this.children.length){
            //图片已经显示完毕.
            this.skipHint();
            //最后一次提示坠地.
            this.player.drop();
        }
    },

    //提示三的玩家指定方向跳跃.
    playerJump: function(e){
        console.log(this.player);
        //this.player.jump(cc.v2(0,-326.3));
        this.player.jump(0);
        //跳跃过程隐藏该页提示.
        this.children[this.currentPage].active = false;
        //cc.director.pause();
    },

    onCollisionEnter: function(other, self){
        //检测角色是否进入了区域范围.
        if(other.tag == 1){
            this.player.pause();
            this.turnNextHint();
        }
    },

});
